package handler;

public class _Test {

	public static void main(String[] argz) {
		// test1();
		//
		 test2(new onDataReady() {
			 @Override
			 public void setData(Object obj) {
				 String str = (String)obj;
				 log(str);
			 }
		 });

	}

	private static void test1() {
		final Handler handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				log("handleMessage()");
				switch (msg.what) {
				case 0:
					break;
				case 1:
					log((String) msg.obj);
					break;
				case 2:
					break;
				}
			}
		};
		new Thread(new Runnable() {
			@Override
			public void run() {
				log("run()");
				handler.sendMessage(Message.Obtain(handler, 1, "abcde"));
				return;
			}
		}).start();
	}

	private static void test2(final onDataReady onDataReady) {
		final Handler handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				log("handleMessage()");
				switch (msg.what) {
				case 0:
					break;
				case 1:
					// log((String)msg.obj);
					onDataReady.setData(msg.obj);
					break;
				case 2:
					break;
				}
			}
		};
		new Thread(new Runnable() {
			@Override
			public void run() {
				log("run()");
				handler.sendMessage(Message.Obtain(handler, 1, "abcde"));
				return;
			}
		}).start();
	}

	public static void log() {
		System.out.println();
	}

	public static void log(Object obj) {
		System.out.println(obj);
	}

	public interface onDataReady {
		public void setData(Object obj);
	}
}